using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Atom.Data.ManagerObjects;
using Atom.Data.BusinessObjects;
using Atom.Data.Base;

namespace Atom.Data.UnitTests
{
	[TestFixture]
    public partial class HBalanceRecordTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetHBalanceRecordManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected Atom.Data.ManagerObjects.IHBalanceRecordManager manager;
		
		protected Atom.Data.BusinessObjects.HBalanceRecord CreateNewHBalanceRecord()
		{
			Atom.Data.BusinessObjects.HBalanceRecord entity = new Atom.Data.BusinessObjects.HBalanceRecord();
			
			
			entity.Balanceid = 92;
			entity.Operatetype = 11;
			entity.Invoiceid = "Test Tes";
			entity.Inhosid = "Test Test T";
			entity.Currentinhosmark = 72;
			entity.Leavehosdate = System.DateTime.Now;
			entity.Inhosdays = 91;
			entity.Balancedate = System.DateTime.Now;
			entity.Totalconsumemoney = 93;
			entity.Paymentmoney = 18;
			entity.Infactmoney = 60;
			entity.Cashreturn = 41;
			entity.Chequereturn = 72;
			entity.Operatedate = System.DateTime.Now;
			entity.Operatorid = "Test Te";
			entity.Cashadvance = 96;
			entity.Chequeadvance = 67;
			entity.Patchmoney = 22;
			entity.Discountpay = 11;
			entity.Personalmoney = 69;
			entity.Agreementmoney = 64;
			entity.Outhosarrearage = 24;
			entity.Yeardiscountpayaccumulative = 69;
			entity.Yeardiscountpaymoney = 2;
			entity.Startmoney = 69;
			entity.Medicareaccumulativemoney = 92;
			entity.Personalaccountpay = 25;
			entity.Midaccountmark = 98;
			entity.Marginmoney = 3;
			entity.Prepay1 = 55;
			entity.Prepay2 = 23;
			entity.Prepay3 = 45;
			entity.Prepay4 = 76;
			entity.Prepay5 = 72;
			entity.Prepay6 = 22;
			entity.Prepay0 = "Test Test ";
			entity.Specialmoney = 92;
			
			return entity;
		}
		protected Atom.Data.BusinessObjects.HBalanceRecord GetFirstHBalanceRecord()
        {
            IList<Atom.Data.BusinessObjects.HBalanceRecord> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Atom.Data.BusinessObjects.HBalanceRecord entity = CreateNewHBalanceRecord();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Atom.Data.BusinessObjects.HBalanceRecord entityA = CreateNewHBalanceRecord();
				manager.Save(entityA);

                Atom.Data.BusinessObjects.HBalanceRecord entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Atom.Data.BusinessObjects.HBalanceRecord entityA = GetFirstHBalanceRecord();
				
				entityA.Inhosid = "Test Test T";
				
				manager.Update(entityA);

                Atom.Data.BusinessObjects.HBalanceRecord entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Balanceid, entityB.Balanceid);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Atom.Data.BusinessObjects.HBalanceRecord entity = GetFirstHBalanceRecord();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

